fix(tracing): Fix unsampled/deferred trace propagation in span streaming#6757
fix(tracing): Fix unsampled/deferred trace propagation in span streaming#6757sentrivana wants to merge 16 commits into
Conversation
Codecov Results 📊✅ 90184 passed | ⏭️ 6302 skipped | Total: 96486 | Pass Rate: 93.47% | Execution Time: 314m 32s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 96.97%. Project has 2436 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.76% 89.78% +0.02%
==========================================
Files 192 192 —
Lines 23823 23833 +10
Branches 8226 8232 +6
==========================================
+ Hits 21384 21397 +13
- Misses 2439 2436 -3
- Partials 1351 1348 -3Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 46b410a. Configure here.
| trace_id=propagation_context.trace_id, | ||
| parent_span_id=propagation_context.parent_span_id, | ||
| parent_sampled=propagation_context.parent_sampled, | ||
| baggage=propagation_context.baggage, |
There was a problem hiding this comment.
Ignored spans wrong trace propagation
Medium Severity
Segment-level ignored spans create an active NoOpStreamedSpan without a propagation sampled value, so it defaults to False. Outgoing headers now come from that noop via _to_traceparent, which uses sampled, not parent_sampled. Downstream traces can be marked unsampled even when the incoming trace was sampled or should stay deferred.
Reviewed by Cursor Bugbot for commit 46b410a. Configure here.
|
Converting to draft to address bot comments |


Description
The SDK didn't behave correctly in some trace propagation scenarios in stream mode.
The current SDK design was emitting headers with a deferred sampling decision if the sampling decision was negative (whether inherited or not), because it was falling back to TWP behavior too eagerly.
How it should be working
In the following, tracing enabled means either a
traces_sample_rateor atraces_sampleris defined. Tracing disabled means both areNoneand tracing without performance is active.There are three kinds of sampling decisions: sampled (
1), unsampled (0), and deferred (``), meaning no decision.The fix
NoOpStreamedSpansnow carry their own trace and span ID information as well as the current propagation data (a snapshot of the propagation context, likeStreamedSpans) and use it to emit the correct headers.Issues
Closes #6755
Reminders
uv run ruff.feat:,fix:,ref:,meta:)